﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using FastDATA;

namespace FastAdmin
{
    /// <summary>
    /// Interaction logic for ListaAlunos.xaml
    /// </summary>
    public partial class ListaAlunos : Window
    {
        public ListaAlunos()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                buscaTodosAlunos();
            }
            catch (Exception)
            {
                throw;
            }
        }

        private void buscaTodosAlunos()
        {
            try
            {
                DCCursoDataContext banco = new DCCursoDataContext();
                List<DEAluno> lista = banco.DEAlunos.ToList();
                dgAlunos.ItemsSource = lista;
            }
            catch (Exception ex)
            {
                GenericActions.TreatError(ex);
            }
        }

        private void btnDetalhar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                detalharAluno();
            }
            catch (Exception ex)
            {
                GenericActions.TreatError(ex);
            }
        }

        private void dgAlunos_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            try
            {
                detalharAluno();
            }
            catch (Exception ex)
            {
                GenericActions.TreatError(ex);
            }
        }

        private void detalharAluno()
        {
            try
            {
                if (dgAlunos.SelectedItems.Count == 0)
                    MessageBox.Show("Selecione um aluno.");
                else
                {
                    DEAluno entidade = (DEAluno)dgAlunos.SelectedItem;

                    GerenciarAluno view = new GerenciarAluno();
                    view.aluno = entidade;
                    view.ShowDialog();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
